package com.guaika.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guaika.reggie.common.ResultMessage;
import com.guaika.reggie.common.StringChars;
import com.guaika.reggie.entity.Employee;
import com.guaika.reggie.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;

/**
 * @author GuaiKa
 */
@Slf4j
@RestController
@RequestMapping("/employee")
public class EmployeeController {
    @Autowired
    EmployeeService employeeService;

    /***
     * 登录方法
     * @param request
     * @param employee
     * @return
     */
    @PostMapping("/login")
    public ResultMessage<Employee> login(HttpServletRequest request , @RequestBody Employee employee){
        return employeeService.login(request,employee);
    }

    /***
     * 退出登录
     * @param request
     * @return
     */
    @PostMapping("/logout")
    public ResultMessage<String> logout(HttpServletRequest request){
        request.getSession().removeAttribute(StringChars.EMPLOYEE.getStr());
        return ResultMessage.success(StringChars.LOGOUT_SUCCESS.getStr());
    }

    @PostMapping
    public ResultMessage<String> save(HttpServletRequest request,@RequestBody Employee employee){
        return employeeService.employeeSave(request, employee);
    }



    @GetMapping("/page")
    public ResultMessage<Page> page(int page,int pageSize,String name){
        return employeeService.employeePage(page, pageSize, name);
    }


    @PutMapping
    public ResultMessage<String> update(@RequestBody Employee employee,HttpServletRequest request){
        return employeeService.employeeUpdate(employee, request);
    }


    /***
     * 根据id获取用户信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResultMessage<Employee> queryById(@PathVariable Long id){
        return employeeService.employeeQueryById(id);
    }



}
